package bkq.viettravel.bll;

import java.util.ArrayList;

import android.content.Context;
import android.database.Cursor;
import android.util.Log;
import bkq.viettravel.database.SqliteServices;
import bkq.viettravel.dto.ProvinceDTO;
import bkq.viettravel.dto.TravelDTO;
import bkq.viettravel.interf.IObjectCommon;

public class TravelBLL implements IObjectCommon<TravelDTO>{
	
	SqliteServices servies = null;
	
	public TravelBLL(Context context) {
		servies = new SqliteServices(context);
	}

	@Override
	public ArrayList<TravelDTO> getAll(String sql) {
		
		ArrayList<TravelDTO> temp = new ArrayList<TravelDTO>();
		
		TravelDTO travel = null;
		
		Cursor c=this.servies.queryData(sql);
		
		if(c != null)
		{
			if(c.moveToFirst())
			{
			 do
			 {
				travel=new TravelDTO();
				travel.setId(Integer.parseInt(c.getString(c.getColumnIndex("id"))));
				travel.setTravelName(c.getString(c.getColumnIndex("name")));
				travel.setTravelSlogan(c.getString(c.getColumnIndex("slogant")));
				travel.setIntroduce(c.getString(c.getColumnIndex("introduce")));
				travel.setImageIntroduce(c.getString(c.getColumnIndex("image")));
				travel.setLongitude(c.getString(c.getColumnIndex("longitude")));
				travel.setLatitude(c.getString(c.getColumnIndex("latitude")));
				travel.setIdProvince(Integer.parseInt(c.getString(c.getColumnIndex("idProvince"))));				
				

				temp.add(travel);
				 
			 }while(c.moveToNext());
			 c.close();
		}
		}
		
		return temp.size() == 0? null : temp;
	}

	@Override
	public ArrayList<TravelDTO> getAll() {
		return getAll("select * from Travel");
	}
	
	public TravelDTO getById(int id)
	{
		ArrayList<TravelDTO> tmp = getAll("select * from Travel where id = "+id+"");
		return tmp.get(0);
	}
	
	@Override
	public boolean insert(TravelDTO obj) {
		// TODO Auto-generated method stub
		return false;
	}

}
